package br.ucb.cm.board.bean;

import java.util.Map;
import java.util.Map.Entry;

import br.ucb.cm.board.util.BoardUtil;
import br.ucb.cm.config.bean.PieceConfig;
import br.ucb.cm.main.common.GeneralConstants.PlayerEnum;

public class PieceMap implements Cloneable{
	private long points;
	Map<Location, PieceConfig> pieceMap;
	
	public PieceMap(Map<Location, PieceConfig> pieceMap) {
		super();
		this.points = 0;
		this.pieceMap = pieceMap;
	}

	public Map<Location, PieceConfig> getPieceMap() {
		return pieceMap;
	}

	public void setPieceMap(Map<Location, PieceConfig> pieceMap) {
		this.pieceMap = pieceMap;
	}

	public long getPoints() {
		return points;
	}

	public void setPoints(long points) {
		this.points = points;
	}

	public boolean hasWinner() {
		boolean hasNoP1 = true, hasNoP2 = true;
		
		for (Entry<Location, PieceConfig> entry : getPieceMap().entrySet()) {
			if (hasNoP1 && BoardUtil.getOwner(entry.getValue()) == PlayerEnum.PLAYER_ONE)
				hasNoP1 = false;
			if (hasNoP2 && BoardUtil.getOwner(entry.getValue()) == PlayerEnum.PLAYER_TWO)
				hasNoP2 = false;
		}
		
		return hasNoP1 || hasNoP2;
	}


}
